// 管理mock数据，课程管理
import * as mUtils from '@/util/mUtils'
let courseRecord=[];
const num=100
for(let i=1;i<=num;i++){
    courseRecord.push({
        courseId:i.toString(),
        name:'数据结构'+i.toString(),
        code:"RNG+IG"+i.toString(),
    });
}
export default {
    courseDownload: () => ({ // 模拟返回下载Excel模板数据
        code: 1,
        msg: "下载成功"
    }),
    courseUpload: () => ({ // 模拟上传Excel模板
        code: 1,
        msg: "上传成功",
        data:{
            data: [
                {
                    courseId: 1,
                    name: "操作系统",
                    code: "asljkdgn"
                },
                {
                    courseId: 2,
                    name: "数据结构",
                    code: "asofhiwng"
                },
                {
                    courseId: 3,
                    name: "数据结构",
                    code: "asofhiwng"
                },
                {
                    courseId: 4,
                    name: "数据结构",
                    code: "asofhiwng"
                },
                {
                    courseId: 5,
                    name: "数据结构",
                    code: "asofhiwng"
                },
                {
                    courseId: 6,
                    name: "数据结构",
                    code: "asofhiwng"
                },
                {
                    courseId: 7,
                    name: "数据结构",
                    code: "asofhiwng"
                },
                {
                    courseId: 8,
                    name: "数据结构",
                    code: "asofhiwng"
                },
                {
                    courseId: 9,
                    name: "数据结构",
                    code: "asofhiwng"
                },
                {
                    courseId: 10,
                    name: "数据结构",
                    code: "asofhiwng"
                },
                {
                    courseId: 11,
                    name: "数据结构",
                    code: "asofhiwng"
                },
                {
                    courseId: 12,
                    name: "数据结构",
                    code: "asofhiwng"
                },
                {
                    courseId: 13,
                    name: "数据结构",
                    code: "asofhiwng"
                }
            ]
        }
    }),
    courseImport: () => ({ // 课程导入
        code: 1,
        msg: "导入成功"
    }),
    getCourseList: config => {
        //token，collegeId
        const { currentPage, rows } = mUtils.param2Obj(config.url);
        const list = courseRecord.filter((item,index) => index < rows * currentPage && index >= rows * (currentPage - 1));
        return {
            data:{
                courseRecord:list,
                count:courseRecord.length,
            },
            code:1,
            msg:'查询成功'
        }
    },
    deleteCourse:config=>{
        //token
        const { courseId} = mUtils.param2Obj(config.url);
        courseRecord=courseRecord.filter(item=>item.courseId!==courseId);
        return {
            data:{},
            code:1,
            msg:'删除课程成功'
        }
    },
    queryCourse:config=>{
        //token,collegeId,courseName
        const { courseName,currentPage, rows } = mUtils.param2ObjPost(config.body);
        const conlist=courseRecord.filter(item=>item.name.includes(courseName));
        const list = conlist.filter((item,index) => index < rows * currentPage && index >= rows * (currentPage - 1))
        return {
            data:{
                courseRecord:list,
                count:conlist.length
            },
            code:1,
            msg:'查找课程成功'
        }
    },
    addCourse:config=>{
        const imf = mUtils.param2ObjPost(config.body);
        const info={
            courseId:(Math.floor(Math.random()*100)+100).toString(),
            name:imf['courseRecord[name]'],
            code:imf['courseRecord[code]'],
        };
        courseRecord.unshift(info);
        return {
            data:{
            },
            code:1,
            msg:'添加课程成功'
        }
    },
    modifyCourse:config=>{
        const imf = mUtils.param2ObjPost(config.body);
        courseRecord.some(item=>{
            if(item.courseId===imf['courseRecord[courseId]']){
                item.name=imf['courseRecord[name]'];
                item.code=imf['courseRecord[code]'];
            }
        });
        return {
            data:{

            },
            code:1,
            msg:'修改课程成功'
        }
    },
    batchDeleteCourse:config=>{
        let ids = mUtils.param2ObjPost(config.body);
        const num=[];
        for(let key in ids){
            num.push(ids[key])
        }
        courseRecord=courseRecord.filter(item=>!num.includes(item.courseId))
        return {
            data:{

            },
            code:1,
            msg:'批量删除课程成功'
        }
    },
}
